package enccompress

import (
	"io/ioutil"
	"path/filepath"

	"roger.com/test-compress/compress"
	"roger.com/test-compress/enc"
)

func EncCompress(path string, key []byte) error {
	err := compress.Gzip(path)
	if err != nil {
		return err
	}
	content, err := ioutil.ReadFile(filepath.Base(path) + ".tar.gz")
	if err != nil {
		return err
	}

	data, err := enc.AesEncrypt(content, key)
	if err != nil {
		return err
	}
	err = ioutil.WriteFile(filepath.Base(path)+".aes", data, 0666)
	if err != nil {
		return err
	}
	return nil
}
